package com.cloudsigns.factorymanager2.produce.presenter;

import android.os.Handler;

import com.cloudsigns.factorymanager2.produce.bean.WorkPartBean;
import com.cloudsigns.factorymanager2.produce.iview.IGetProductWorkPartListView;
import com.cloudsigns.factorymanager2.produce.model.GetProductWorkPartListModel;
import com.cloudsigns.factorymanager2.produce.model.IGetProductWorkPartListModel;
import com.cloudsigns.factorymanager2.project.bean.ProductBean;

import java.util.List;

public class GetProductWorkPartListPresenter {
    private IGetProductWorkPartListView view;
    private IGetProductWorkPartListModel model;
    private Handler handler = new Handler();

    public GetProductWorkPartListPresenter(IGetProductWorkPartListView iView) {
        this.view = iView;
        this.model = new GetProductWorkPartListModel();
    }

    public void getProductWorkPartList() {
        model.getProductWorkPartList(new GetProductWorkPartListModel.OnGetProductWorkPartListListListener() {
            @Override
            public void getDataSuccessed(final List<WorkPartBean> productOrderBeanList) {
                handler.post(new Runnable() {
                    @Override
                    public void run() {
                        view.getDataSuccessed(productOrderBeanList);
                        view.hideLoading();
                    }
                });
            }

            @Override
            public void getDataFailed(final String desc) {
                handler.post(new Runnable() {
                    @Override
                    public void run() {
                        view.showFailedError(desc);
                        view.hideLoading();
                    }
                });
            }
        });
    }
}
